package com.easy.service.impl;

import com.easy.bean.Inventory;
import com.easy.dao.IInventoryDao;
import com.easy.service.IInventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service

public class InventoryImpl implements IInventoryService {
    @Autowired
    private IInventoryDao dao;
    @Override
    public Inventory getInventoryByProductId(String product_id) {
        Inventory inventory = dao.getInventoryByProductId(product_id);
        if (inventory == null) {
            // 如果找不到该商品，返回一个新的空对象或者抛出异常
            throw new RuntimeException("商品未找到: " + product_id);
        }
        return inventory;
    }


    @Override
    public List<Inventory> getPagedInventory(int page, int size) {
        int offset = (page - 1) * size;// 计算 offset
        return dao.getPagedInventory(offset, size);
    }
    @Override
    public int getTotalInventoryCount() {
        return dao.getTotalInventoryCount();
    }

    @Override
    public List<Inventory> searchInventory(String keyword) {
        return dao.searchInventory(keyword);
    }
}
